package email;

public class DateObject {
	private int month;
	private int day;
	private int year;
	private int hours;
	private int minutes;
	private int seconds;
	
	public DateObject(ReceivedMessage msg){
		String date1 = msg.getDate();
		String[] date1Split = date1.split(" ");
	
		String month_s = date1Split[1];
		month = getMonthNumber(month_s);
		String day_s = date1Split[2];
		day = parseInt(day_s);
		String[] time = date1Split[3].split(":");
		hours = parseInt(time[0]);
		minutes = parseInt(time[1]);
		seconds = parseInt(time[2]);
		
		String year_s = date1Split[5];
		year = parseInt(year_s);
	}
	
	public int getMonth(){
		return month;
	}
	public int getDay(){	
		return day;
	}
	public int getHours(){
		return hours;
	}
	public int getMinutes(){
		return minutes;
	}
	public int getSeconds(){
		return seconds;
	}
	public int getYear(){
		return year;
	}
	
	private int parseInt(String integer){
		int toReturn = 0;
		try{
			toReturn = Integer.parseInt(integer);
		}
		catch(Exception e){
			toReturn = 0;
		}
		return toReturn;
	}
		
	private int getMonthNumber(String month){
		int number = 0;
		
		if(month.contains("Jan")){
			number = 1;
		}else if(month.contains("Feb")){
			number = 2;
		}else if(month.contains("Mar")){
			number = 3;
		}else if(month.contains("Apr")){
			number = 4;
		}else if(month.contains("May")){
			number = 5;
		}else if(month.contains("Jun")){
			number = 6;
		}else if(month.contains("Jul")){
			number = 7;
		}else if(month.contains("Aug")){
			number = 8;
		}else if(month.contains("Sep")){
			number = 9;
		}else if(month.contains("Oct")){
			number = 10;
		}else if(month.contains("Nov")){
			number = 11;
		}else if(month.contains("Dec")){
			number = 12;
		}
		
		return number;
	}
}
